package xymt.novaway.system.aspect;

/**
 * 数据权限过滤条件
 *
 * @author 系统
 * @date 2025-01-19
 */
public class DataScopeFilter {
    
    private static final ThreadLocal<String> DATA_SCOPE_SQL = new ThreadLocal<>();
    private static final ThreadLocal<String> FIELD_NAME = new ThreadLocal<>();
    
    /**
     * 设置数据权限SQL
     */
    public static void setDataScopeSQL(String sql, String fieldName) {
        DATA_SCOPE_SQL.set(sql);
        FIELD_NAME.set(fieldName);
    }
    
    /**
     * 获取数据权限SQL
     */
    public static String getDataScopeSQL() {
        return DATA_SCOPE_SQL.get();
    }
    
    /**
     * 获取字段名
     */
    public static String getFieldName() {
        return FIELD_NAME.get();
    }
    
    /**
     * 清除数据权限SQL
     */
    public static void clearDataScopeSQL() {
        DATA_SCOPE_SQL.remove();
        FIELD_NAME.remove();
    }
    
    /**
     * 检查是否有活跃的数据权限过滤
     */
    public static boolean hasActiveFilter() {
        return DATA_SCOPE_SQL.get() != null;
    }
}